<?php
/**
 * Created by PhpStorm.
 * User: chenyeubin
 * Date: 2020\2\17 0017
 * Time: 10:35
 */

namespace api\modules\v1\controllers\patient;

use common\models\marketing\RiskType;
use common\models\member\Attr;
use Fxp\Composer\AssetPlugin\Installer\IgnoreFactory;
use services\common\CommonService;
use Yii;
use common\helpers\CommonHelper;
use common\models\patient\User;
use common\models\base\Profession;
use common\models\member\Member;
use common\models\patient\Callback;
use common\models\statistics\CallbackReport;
use api\controllers\OnAuthController;
use yii\web\HttpException;

class PatientCallbackController extends OnAuthController
{
    /**
     * @var string
     */
    public $modelClass = User::class;

    /**
     * v1/patient/patient-callback/re-follow 待回访
     * 待回访列表
     * @return array
     * cyb
     * @apiParam {String} start_time                                       开始时间【格式：2020-01-01】
     * @apiParam {String} end_time                                         结束时间【格式：2020-01-01】
     * @apiParam {String} keywords                                         关键词【姓名or手机号】
     * @apiParam {String} belong_member_id                                 归属人id
     * @apiParam {Number} outpatient_type_id                               就诊类型
     * @apiParam {Number} tags_id                                          标签【多个以,逗号隔开】
     * @apiParam {Number} last_revisiting_time_type                        上次到诊时间排序【0默认、1顺序、2倒序】
     * @apiParam {Number} next_revisiting_time_type                        下次复诊时间排序【0默认、1顺序、2倒序】
     * @apiParam {Number} last_callback_time_type                          上次回访时间排序【0默认、1顺序、2倒序】
     * @apiParam {Number} next_callback_time_type                          下次回访时间排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_revisiting_type                             复诊次数排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_missed_type                                 未到诊天数排序【0默认、1顺序、2倒序】
     * @apiParam {Number} page                                             页码
     * @apiParam {Number} pageSize
     */
    public function actionReFollowList()
    {
        $params = Yii::$app->request->get();
        $params['project_id'] = $this->projectId;
        $params['keywords'] = $params['keywords'] ?? '';
        $params['outpatient_type_id'] = $params['outpatient_type_id'] ?? 0;
        $page = $params['page'] ?? 1;
        $pageSize = $params['pageSize'] ?? 10;
        $params['in_hospital'] = $params['in_hospital'] ?? 0;

        // 获取筛选条件
        $conditionParams = [
            'get_hospital' => 1,
        ];
        if ($params['customer'] == 1) {
            $conditionParams['get_customer_member'] = 1;
        } else {
            $conditionParams['get_medical_member'] = 1;
        }
        $isCheckType = Yii::$app->user->identity->member->is_super == Member::IS_SUPER_NO ? 1 : 0;

        // 是否返回客服就诊类型
        $isCustomer = Yii::$app->params['is_customer'];

        $condition = Yii::$app->services->patientUser->getConditionList($conditionParams, $this->projectId, $isCheckType);
        $condition['outpatient_type_list'] = CommonService::getOutpatientTypeList($isCustomer);
        $condition['tags_list'] = CommonService::getTagsList();

        // 查询结果
        if (empty($params['keywords']) && empty($params['outpatient_type_id'])) {
            $params['outpatient_type_id'] = array_column($condition['outpatient_type_list'], 'id');
        }
        $params['isCustomer'] = $isCustomer;
        $params['re_follow'] = 1;
        $data = Yii::$app->services->patientCallback->getListPage($params, (int)$page, (int)$pageSize, 0);// 待回访
        // 格式化列表数据
        $data['list'] = Yii::$app->services->patientCallback->getListPageFormat($data['list'], 0, $params['customer']);
        if (isset($condition['member_customer_list'])) {
            $condition['member_list'] = $condition['member_customer_list'];
        } elseif (isset($condition['member_medical_list'])) {
            $condition['member_list'] = $condition['member_medical_list'];
        }
        $data['condition'] = $condition;

        return $data;
    }

    /**
     *
     * v1/patient/patient-callback/follow-list 已回访
     * 回访列表
     * @return array
     * cyb
     * @apiParam {String} start_time                                       开始时间【格式：2020-01-01】
     * @apiParam {String} end_time                                         结束时间【格式：2020-01-01】
     * @apiParam {String} keywords                                         关键词【姓名or手机号】
     * @apiParam {String} belong_member_id                                 归属人id
     * @apiParam {Number} outpatient_type_id                               就诊类型
     * @apiParam {Number} tags_id                                          标签【多个以,逗号隔开】
     * @apiParam {Number} last_revisiting_time_type                        上次到诊时间排序【0默认、1顺序、2倒序】
     * @apiParam {Number} next_revisiting_time_type                        下次复诊时间排序【0默认、1顺序、2倒序】
     * @apiParam {Number} last_callback_time_type                          上次回访时间排序【0默认、1顺序、2倒序】
     * @apiParam {Number} next_callback_time_type                          下次回访时间排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_revisiting_type                             复诊次数排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_missed_type                                 未到诊天数排序【0默认、1顺序、2倒序】
     * @apiParam {Number} page                                             页码
     * @apiParam {Number} pageSize
     */
    public function actionFollowList()
    {
        $params = Yii::$app->request->get();
        $params['project_id'] = $this->projectId;
        $params['keywords'] = $params['keywords'] ?? '';
        $params['outpatient_type_id'] = $params['outpatient_type_id'] ?? 0;
        $page = $params['page'] ?? 1;
        $pageSize = $params['pageSize'] ?? 10;
        $params['in_hospital'] = $params['in_hospital'] ?? 0;

        // 获取筛选条件
        $conditionParams = [
            'get_hospital' => 1,
        ];
        if ($params['customer'] == 1) {
            $conditionParams['get_customer_member'] = 1;
        } else {
            $conditionParams['get_medical_member'] = 1;
        }
        $isCheckType = Yii::$app->user->identity->member->is_super == Member::IS_SUPER_NO ? 1 : 0;

        // 是否返回客服就诊类型
        $isCustomer = Yii::$app->params['is_customer'];
        if (Yii::$app->params['is_customer'] == 1) {// 客服
            $conditionParams['get_customer_member'] = 1;
        }

        $condition = Yii::$app->services->patientUser->getConditionList($conditionParams, $this->projectId, $isCheckType);
        $condition['outpatient_type_list'] = CommonService::getOutpatientTypeList($isCustomer);
        $condition['tags_list'] = CommonService::getTagsList();

        // 查询结果
        if (empty($params['keywords']) && empty($params['outpatient_type_id'])) {
            $params['outpatient_type_id'] = array_column($condition['outpatient_type_list'], 'id');
        }

        $params['isCustomer'] = $isCustomer;
        $data = Yii::$app->services->patientCallback->getListPage($params, (int)$page, (int)$pageSize, 1);// 已回访
        // 格式化列表数据
        $data['list'] = Yii::$app->services->patientCallback->getListPageFormat($data['list'], 0, $params['customer']);
        if (isset($condition['member_customer_list'])) {
            $condition['member_list'] = $condition['member_customer_list'];
        } elseif (isset($condition['member_medical_list'])) {
            $condition['member_list'] = $condition['member_medical_list'];
        }
        $data['condition'] = $condition;

        return $data;
    }

    /**
     * @api {post} /v1/patient/patient-callback/follow 回访
     * @apiName follow
     * @apiGroup Patient
     *
     * @apiParam {Number} patient_id                 患者id
     * @apiParam {Number} callback_state_id          回访状态id
     * @apiParam {Number} callback_way_id            回访方式id
     * @apiParam {String} content                    回访内容
     * @apiParam {Number} outpatient_type_id         就诊类型id
     * @apiParam {String} next_callback_time         下次回访时间
     * @apiParam {String} next_fuzhen_time           下次复诊时间
     *
     * @apiSuccess {Object}  data                    返回数据
     * @apiSuccess {Number}  data.id                 患者ID
     */
    public function actionToFollow()
    {
        $params = Yii::$app->request->post();
        $params['project_id'] = $this->projectId;
        $is_vitiligo_not = $params['is_vitiligo_not'] ?? false;
        $is_first_initially = $params['is_first_initially'] ?? false;
        if (!$params['patient_id']) {
            throw new HttpException(422, '请选择要回访的患者');
        }
        if (!$params['callback_state_id']) {
            throw new HttpException(422, '请选择回访状态');
        }
        if (!$params['callback_way_id']) {
            throw new HttpException(422, '请选择回访方式');
        }
        if (!$params['content']) {
            throw new HttpException(422, '请填写回访内容');
        }
        if (!isset($params['risk_type']) || !$params['risk_type']) {
            throw new HttpException(422, '请选择风控类型');
        }
        // 不是初诊/非白 必填
        if ((!$is_vitiligo_not && !$is_first_initially) && (!isset($params['effect_type']) || !$params['effect_type'])) {
            throw new HttpException(422, '请选择效果类型');
        }
        // 如果风控类型不是黑名单，则下次回访时间为必填
        if ($params['risk_type'] != RiskType::BLACK_LIST && !$params['next_callback_time']) {
            throw new HttpException(422, '请选择下次回访时间');
        }
        $params['outpatient_type_id'] = !isset($params['outpatient_type_id']) ? 0 : $params['outpatient_type_id'];
        $params['next_fuzhen_time'] = !isset($params['next_fuzhen_time']) ? 0 : $params['next_fuzhen_time'];
        // 如果风控类型不是黑名单，则判断下次回访时间的有效性
        if ($params['risk_type'] != RiskType::BLACK_LIST) {
            if (strtotime($params['next_callback_time']) < strtotime(date("Y-m-d"))) {
                throw new HttpException(422, '下次回访时间不能是过去时间');
            }
        }

        if ($params['next_fuzhen_time'] && strtotime($params['next_fuzhen_time']) < strtotime(date("Y-m-d"))) {
            throw new HttpException(422, '下次复诊时间不能是过去时间');
        }
        $checkPatient = Yii::$app->services->patientUser->findById($params['patient_id']);
        if (!$checkPatient) {
            throw new HttpException(422, '未找到该患者信息');
        }

        if (!Yii::$app->params['is_assistant'] && !Yii::$app->params['is_customer']) {
            return CommonHelper::api(422, '非医助和客服无法回访');
        }

        // 是否返回客服就诊类型
        $params['isCustomer'] = Yii::$app->params['is_customer'];
        $res = Yii::$app->services->patientCallback->createFollow($params);

        return $res;
    }

    /**
     * 过期未回访列表
     * @return array
     * cyb
     * @apiParam {String} unfollow_time                                    未回访时间【1：昨天，2:10天以内，3:10~20天，4:20天~40天，5:40天~60天，6:60天以上】
     * @apiParam {String} keywords                                         关键词【姓名or手机号】
     * @apiParam {String} belong_member_id                                 归属人id
     * @apiParam {Number} outpatient_type_id                               就诊类型
     * @apiParam {Number} tags_id                                          标签【多个以,逗号隔开】
     * @apiParam {Number} last_revisiting_time_type                        上次到诊时间排序【0默认、1顺序、2倒序】
     * @apiParam {Number} next_revisiting_time_type                        下次复诊时间排序【0默认、1顺序、2倒序】
     * @apiParam {Number} last_callback_time_type                          上次回访时间排序【0默认、1顺序、2倒序】
     * @apiParam {Number} next_callback_time_type                          下次回访时间排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_revisiting_type                             复诊次数排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_missed_type                                 未到诊天数排序【0默认、1顺序、2倒序】
     * @apiParam {Number} sort_unfollow_type                               过期天数排序【0默认、1顺序、2倒序】
     * @apiParam {Number} page                                             页码
     * @apiParam {Number} pageSize
     */
    public function actionUnFollow()
    {
        $params = Yii::$app->request->get();
        $params['project_id'] = $this->projectId;
        $page = $params['page'] ?? 1;
        $pageSize = $params['pageSize'] ?? 10;

        if (!isset($params['unfollow_time'])) {
            $params['unfollow_time'] = 0;
        }
        $params['in_hospital'] = $params['in_hospital'] ?? 0;

        // 获取筛选条件
        $conditionParams = [
            'get_hospital' => 1,
        ];
        if ($params['customer'] == 1) {
            $conditionParams['get_customer_member'] = 1;
        } else {
            $conditionParams['get_medical_member'] = 1;
        }
        $isCheckType = Yii::$app->user->identity->member->is_super == Member::IS_SUPER_NO ? 1 : 0;

        // 是否返回客服就诊类型
        $isCustomer = Yii::$app->params['is_customer'];

        $condition = Yii::$app->services->patientUser->getConditionList($conditionParams, $this->projectId, $isCheckType);
        $condition['outpatient_type_list'] = CommonService::getOutpatientTypeList($isCustomer);
        $condition['tags_list'] = CommonService::getTagsList();

        // 查询结果
        if (empty($params['keywords']) && empty($params['outpatient_type_id'])) {
            $params['outpatient_type_id'] = array_column($condition['outpatient_type_list'], 'id');
        }
        $params['isCustomer'] = $isCustomer;
        $data = Yii::$app->services->patientCallback->getUnfollowListPage($params, (int)$page, (int)$pageSize);// 已回访

        // 格式化列表数据
        $data['list'] = Yii::$app->services->patientCallback->getListPageFormat($data['list'], 1, $params['customer']);
        if (isset($condition['member_customer_list'])) {
            $condition['member_list'] = $condition['member_customer_list'];
        } elseif (isset($condition['member_medical_list'])) {
            $condition['member_list'] = $condition['member_medical_list'];
        }
        $data['condition'] = $condition;

        return $data;
    }

    /**
     * @api {get} /v1/patient/patient-callback/report-info          回访报表信息【回访报表之前请求】
     * @apiName report-info
     * @apiGroup PatientCallback
     *
     *
     * @apiSuccess {Object}  data                                   返回数据
     * @apiSuccess {Number}  data.profession_type                   岗位类型【0其他、1客服、2医助】
     * @apiSuccess {Array}   data.profession_list                   岗位列表
     */
    public function actionReportInfo()
    {
        $params = Yii::$app->request->get();
        $params['project_id'] = $this->projectId;

        return Yii::$app->services->statisticsCallbackReport->getReportInfo($params);
    }

    /**
     * @api {get} /v1/patient/patient-callback/report-list          回访报表
     * @apiName report-list
     * @apiGroup PatientCallback
     *
     * @apiParam {String} start_time                                开始时间【格式：2020-01-01】
     * @apiParam {String} end_time                                  结束时间【格式：2020-01-01】
     * @apiParam {Number} profession_id                             岗位类型【1客服、2医助】
     *
     * @apiSuccess {Object}  data                                   返回数据
     * @apiSuccess {Number}  data.profession_type                   岗位类型【0其他、1客服、2医助】
     * @apiSuccess {Array}   data.list                              列表
     * @apiSuccess {Number}  data.list.project_id                   项目ID
     * @apiSuccess {Number}  data.list.profession_id                岗位ID【1客服、2医助】
     * @apiSuccess {String}  data.list.pname                        项目名称
     * @apiSuccess {Number}  data.list.callback_num                 回访次数
     * @apiSuccess {Number}  data.list.callback_patient_num         回访人数
     * @apiSuccess {Number}  data.list.normal_callback_rate         正常回访比例
     * @apiSuccess {Object}  data.list.callback_way                 回访方式【key=>val】
     * @apiSuccess {Object}  data.list.callback_state               回访状态【key=>val】
     * @apiSuccess {Object}  data.list.callback_year                回访年份【key=>val】
     * @apiSuccess {Object}  data.total                             合计
     * @apiSuccess {Number}  data.total.callback_num                回访总次数
     * @apiSuccess {Number}  data.total.callback_patient_num        回访总人数
     * @apiSuccess {Object}  data.total.callback_way                回访方式【key=>val】
     * @apiSuccess {Object}  data.total.callback_state              回访状态【key=>val】
     * @apiSuccess {Object}  data.total.callback_year               回访年份【key=>val】
     * @apiSuccess {Object}  data.condition                         条件【列表col】
     * @apiSuccess {Object}  data.condition.callback_way_list       回访方式
     * @apiSuccess {Number}  data.condition.callback_way_list.id    ID
     * @apiSuccess {String}  data.condition.callback_way_list.name  名称
     * @apiSuccess {Object}  data.condition.callback_status_list    回访状态【同上】
     * @apiSuccess {Array}   data.condition.year_list               回访年份['2020', '2019']
     */
    public function actionReportList()
    {
        $params = Yii::$app->request->get();
        $params['start_time'] = $params['start_time'] ?? '';
        $params['end_time'] = $params['end_time'] ?? '';
        $params['profession_id'] = $params['profession_id'] ?? CallbackReport::PROFESSION_ID_MEDICAL;
        $params['project_id'] = $this->projectId;

        return Yii::$app->services->statisticsCallbackReport->getStaticsReportCallbackList($params);


        /*// 回访方式
        $callbackWayIds = Callback::$callbackWayIds;
        $callbackWayIdsStr = [];
        foreach ($callbackWayIds as $key => $row) {
            $callbackWayIdsStr[] = [
                'id' => $key,
                'name' => $row,
            ];
        }

        // 回访状态
        $condition = Yii::$app->services->patientUser->getConditionList(['get_callback_status' => 1], $this->projectId);

        // 统计时间
        $userYear = Yii::$app->services->patientUser->getUserRegTimeYearList([
            'project_id' => $this->projectId,
        ]);

        // 条件
        $condition = [
            'callback_way_list' => $callbackWayIdsStr,
            'callback_status_list' => $condition['callback_status_list'],
            'year_list' => array_column($userYear, 'year'),
        ];

        // 属性
        $attr = Yii::$app->services->attr->findInfo([
            'member_id' => Yii::$app->user->identity->member_id,
            'project_id' => $this->projectId,
        ]);
        // 获取要查询的归属人id
        if ($attr && $attr->is_department_leader == Attr::IS_DEPARTMENT_LEADER_NO) {
            $params['check_member_id'] = [Yii::$app->user->identity->member_id];
        } elseif ($attr && $attr->is_department_leader == Attr::IS_DEPARTMENT_LEADER_YES) {
            $params['check_member_id'] = Yii::$app->services->attr->findMemberId(['project_id' => $this->projectId, 'department_id' => $attr->department_id]);
        }
        // 查询结果
        $data = Yii::$app->services->statisticsCallbackReport->getListPage($params);
        // 格式化数据
        $dataFormat = Yii::$app->services->statisticsCallbackReport->getListPageFormat($data['list'], array_merge($condition, $params));


        $professionId = $attr ? $attr->profession_id : 0;
        $professionType = 0;

        // 返回客服还是医助的列表
        $profession_list = [
            [
                'id' => 2,
                'profession_name' => '医助'
            ],
            [
                'id' => 1,
                'profession_name' => '客服'
            ]
        ];
        if ($professionId == Profession::ID_MEDICAL) {// 医助
            $professionType = 2;
            $profession_list = [
                [
                    'id' => $professionType,
                    'profession_name' => '医助'
                ]
            ];
        } elseif ($professionId == Profession::ID_CUSTOMER) {// 客服
            $professionType = 1;
            $profession_list = [
                [
                    'id' => $professionType,
                    'profession_name' => '客服'
                ]
            ];
        }

        return [
            'profession_type' => $professionType,
            'list' => $dataFormat['list'],
            'total' => $dataFormat['total'],
            'condition' => $condition,
            'profession_list' => $profession_list
        ];*/
    }

    /**
     * @api {get} /v1/patient/patient-callback/time-report-list          回访报表
     * @apiName time-report-list
     * @apiGroup PatientCallback
     *
     * @apiParam {String} start_time                                开始时间【格式：2020-01-01】
     * @apiParam {String} end_time                                  结束时间【格式：2020-01-01】
     * @apiParam {Number} profession_id                             岗位类型【1客服、2医助】
     *
     * @apiSuccess {Object}  data                                   返回数据
     * @apiSuccess {Number}  data.profession_type                   岗位类型【0其他、1客服、2医助】
     * @apiSuccess {Array}   data.list                              列表
     * @apiSuccess {Number}  data.list.project_id                   项目ID
     * @apiSuccess {Number}  data.list.profession_id                岗位ID【1客服、2医助】
     * @apiSuccess {String}  data.list.pname                        项目名称
     * @apiSuccess {Number}  data.list.callback_num                 回访次数
     * @apiSuccess {Number}  data.list.callback_patient_num         回访人数
     * @apiSuccess {Number}  data.list.normal_callback_rate         正常回访比例
     * @apiSuccess {Object}  data.list.callback_way                 回访方式【key=>val】
     * @apiSuccess {Object}  data.list.callback_state               回访状态【key=>val】
     * @apiSuccess {Object}  data.list.callback_year                回访年份【key=>val】
     * @apiSuccess {Object}  data.total                             合计
     * @apiSuccess {Number}  data.total.callback_num                回访总次数
     * @apiSuccess {Number}  data.total.callback_patient_num        回访总人数
     * @apiSuccess {Object}  data.total.callback_way                回访方式【key=>val】
     * @apiSuccess {Object}  data.total.callback_state              回访状态【key=>val】
     * @apiSuccess {Object}  data.total.callback_year               回访年份【key=>val】
     * @apiSuccess {Object}  data.condition                         条件【列表col】
     * @apiSuccess {Object}  data.condition.callback_way_list       回访方式
     * @apiSuccess {Number}  data.condition.callback_way_list.id    ID
     * @apiSuccess {String}  data.condition.callback_way_list.name  名称
     * @apiSuccess {Object}  data.condition.callback_status_list    回访状态【同上】
     * @apiSuccess {Array}   data.condition.year_list               回访年份['2020', '2019']
     */
    public function actionTimeReportList()
    {
        $params = Yii::$app->request->get();
        $params['start_time'] = $params['start_time'] ?? '';
        $params['end_time'] = $params['end_time'] ?? '';
        $params['profession_id'] = $params['profession_id'] ?? CallbackReport::PROFESSION_ID_MEDICAL;
        $params['project_id'] = $this->projectId;

        return Yii::$app->services->statisticsCallbackReport->getTimeReportCallbackList($params);
    }

    /**
     * @api {get} /v1/patient/patient-callback/report-member-list   回访人患者列表
     * @apiName report-member-list
     * @apiGroup PatientCallback
     *
     * @apiParam {Number} member_id                                 回访人ID
     * @apiParam {String} start_time                                开始时间【格式：2020-01-01】
     * @apiParam {String} end_time                                  结束时间【格式：2020-01-01】
     * @apiParam {Number} callback_way_id                           回访方式
     * @apiParam {Number} callback_state_id                         回访状态
     * @apiParam {String} reg_time                                  回访患者年份【'2020'】
     * @apiParam {Number} page                                      页码
     * @apiParam {Number} pageSize                                  每页显示数
     *
     * @apiSuccess {Object}  data                                   返回数据
     * @apiSuccess {Number}  data.page                              当前页码
     * @apiSuccess {Number}  data.pageSize                          每页显示数
     * @apiSuccess {Number}  data.total                             总数
     * @apiSuccess {Array}   data.list                              列表
     * @apiSuccess {Number}  data.list.patient_user_id              患者ID
     * @apiSuccess {String}  data.list.name                         姓名
     * @apiSuccess {String}  data.list.patient_card_id              诊疗号
     * @apiSuccess {String}  data.list.diseases_name                病种名
     * @apiSuccess {String}  data.list.reg_time_str                 初次挂号时间
     * @apiSuccess {String}  data.list.last_revisiting_time_str     上次到诊日期
     * @apiSuccess {String}  data.list.next_revisiting_time_str     下次到诊日期
     * @apiSuccess {Number}  data.list.missed_days                  未到诊天数
     * @apiSuccess {Number}  data.list.callback_num                 回访次数
     * @apiSuccess {Number}  data.list.total_callback_num           总回访次数
     * @apiSuccess {String}  data.list.content                      最近回访内容
     */
    public function actionReportMemberList()
    {
        $params = Yii::$app->request->get();
        $params['member_id'] = $params['member_id'] ?? 0;
        $params['start_time'] = $params['start_time'] ?? '';
        $params['end_time'] = $params['end_time'] ?? '';
        $params['project_id'] = $this->projectId;

        /*$preDate = date('Y-m-d', strtotime('-1 day'));
        if (!$params['end_time']) {
            $params['end_time'] = $preDate;
        } elseif ($params['end_time'] > $preDate) {
            $params['end_time'] = $preDate;
        }*/

        $page = $params['page'] ?? 1;
        $pageSize = $params['pageSize'] ?? 10;

        // 查询结果
        $data = Yii::$app->services->patientCallback->getReportMemberListPage($params, (int)$page, (int)$pageSize);

        // 格式化数据
        $data['list'] = Yii::$app->services->patientCallback->getReportMemberListPageFormat($data['list'], $params);

        return $data;
    }

    /**
     * @api {get} /v1/patient/patient-callback/report-project-list   回访项目患者列表
     * @apiName report-project-list
     * @apiGroup PatientCallback
     *
     * @apiParam {Number} project_id                                项目ID
     * @apiParam {Number} profession_id                             岗位类型【1客服、2医助】
     * @apiParam {String} start_time                                开始时间【格式：2020-01-01】
     * @apiParam {String} end_time                                  结束时间【格式：2020-01-01】
     * @apiParam {Number} callback_way_id                           回访方式
     * @apiParam {Number} callback_state_id                         回访状态
     * @apiParam {String} reg_time                                  回访患者年份【'2020'】
     * @apiParam {Number} page                                      页码
     * @apiParam {Number} pageSize                                  每页显示数
     *
     * @apiSuccess {Object}  data                                   返回数据
     * @apiSuccess {Number}  data.page                              当前页码
     * @apiSuccess {Number}  data.pageSize                          每页显示数
     * @apiSuccess {Number}  data.total                             总数
     * @apiSuccess {Array}   data.list                              列表
     * @apiSuccess {Number}  data.list.patient_user_id              患者ID
     * @apiSuccess {String}  data.list.name                         姓名
     * @apiSuccess {String}  data.list.patient_card_id              诊疗号
     * @apiSuccess {String}  data.list.diseases_name                病种名
     * @apiSuccess {String}  data.list.reg_time_str                 初次挂号时间
     * @apiSuccess {String}  data.list.last_revisiting_time_str     上次到诊日期
     * @apiSuccess {String}  data.list.next_revisiting_time_str     下次到诊日期
     * @apiSuccess {Number}  data.list.missed_days                  未到诊天数
     * @apiSuccess {Number}  data.list.callback_num                 回访次数
     * @apiSuccess {Number}  data.list.total_callback_num           总回访次数
     * @apiSuccess {String}  data.list.content                      最近回访内容
     */
    public function actionReportProjectList()
    {
        $params = Yii::$app->request->get();
        $params['start_time'] = $params['start_time'] ?? '';
        $params['end_time'] = $params['end_time'] ?? '';
        $params['project_id'] = $params['project_id'] ?? 0;
        $params['profession_id'] = $params['profession_id'] ?? CallbackReport::PROFESSION_ID_MEDICAL;

        /*$preDate = date('Y-m-d', strtotime('-1 day'));
        if (!$params['end_time']) {
            $params['end_time'] = $preDate;
        } elseif ($params['end_time'] > $preDate) {
            $params['end_time'] = $preDate;
        }*/

        $page = $params['page'] ?? 1;
        $pageSize = $params['pageSize'] ?? 10;

        // 查询结果
        $data = Yii::$app->services->patientCallback->getReportMemberListPage($params, (int)$page, (int)$pageSize);

        // 格式化数据
        $data['list'] = Yii::$app->services->patientCallback->getReportMemberListPageFormat($data['list'], $params);

        return $data;
    }
}
